﻿<UserControl x:Class="BallOnTiltablePlate.JanRapp.Controls.Visualizer3D"
             x:ClassModifier="internal"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
             xmlns:System="clr-namespace:System;assembly=mscorlib"
             xmlns:local="clr-namespace:BallOnTiltablePlate.JanRapp.Controls.Visualizer"
             xmlns:util="clr-namespace:BallOnTiltablePlate.JanRapp.Utilities.WPF"
             mc:Ignorable="d"
             d:DesignHeight="451" d:DesignWidth="582" Background="#FF1D1D1D" >
    <UserControl.Resources>
        <System:Double x:Key="RotationOfCamera">-150</System:Double>
        <System:Double x:Key="AngleOfCamera">35</System:Double>
        <System:Double x:Key="DistanceOfCamera">-6.2</System:Double>
        <System:Double x:Key="BallSize">0.05</System:Double>
        <System:Double x:Key="BallPositionX">0.0</System:Double>
        <System:Double x:Key="BallPositionY">0.0</System:Double>
        <System:Double x:Key="BallPositionZ">0.0</System:Double>
        <util:VectorToDoubleSplitterConverterToDeg x:Key="VectorToDoubleSplitterConverterToDeg"/>
        <util:Point3DToDoubleSplitterConverter x:Key="Point3DToDoubleSplitterConverter"/>
    </UserControl.Resources>
    <Grid>
        <Viewport3D>
            <Viewport3D.Camera>
                <PerspectiveCamera x:Name="Camera" FieldOfView="45" 
                                    LookDirection="0,1,0" 
                                    UpDirection="0,0,1">
                    <PerspectiveCamera.Transform>
                        <Transform3DGroup>
                            <TranslateTransform3D OffsetY="{DynamicResource DistanceOfCamera}"/>
                            <RotateTransform3D>
                                <RotateTransform3D.Rotation>
                                    <AxisAngleRotation3D Axis="-1,0,0" Angle="{DynamicResource AngleOfCamera}"/>
                                </RotateTransform3D.Rotation>
                            </RotateTransform3D>
                            <RotateTransform3D>
                                <RotateTransform3D.Rotation>
                                    <AxisAngleRotation3D Axis="0,0,1" Angle="{DynamicResource RotationOfCamera}"/>
                                </RotateTransform3D.Rotation>
                            </RotateTransform3D>
                        </Transform3DGroup>
                    </PerspectiveCamera.Transform>
                </PerspectiveCamera>
            </Viewport3D.Camera>
            <local:Plate3D x:Name="PlateModel">
                <local:Plate3D.Transform>
                    <RotateTransform3D>
                        <RotateTransform3D.Rotation>
                            <QuaternionRotation3D x:Name="PlateRotation"/>
                        </RotateTransform3D.Rotation>
                    </RotateTransform3D>
                </local:Plate3D.Transform>
                <local:Plate3D.Material>
                    <DiffuseMaterial>
                        <DiffuseMaterial.Brush>
                            <ImageBrush ImageSource=".\Shapes\PlateTextureBlackAxies.png"/>
                        </DiffuseMaterial.Brush>
                    </DiffuseMaterial>
                </local:Plate3D.Material>
                <local:Plate3D.BackMaterial>
                    <DiffuseMaterial Color="Black" Brush="Black"/>
                </local:Plate3D.BackMaterial>
            </local:Plate3D>
            <local:Sphere3D x:Name="BallModel">
                <local:Sphere3D.Transform>
                    <Transform3DGroup>
                        <ScaleTransform3D ScaleX="{DynamicResource BallSize}" ScaleY="{DynamicResource BallSize}" ScaleZ="{DynamicResource BallSize}"/>
                        <!--<TranslateTransform3D 
                            OffsetX="{Binding Position, Converter={StaticResource Point3DToDoubleSplitterConverter}, ConverterParameter='X', Mode=OneWay}" 
                            OffsetY="{Binding Position, Converter={StaticResource Point3DToDoubleSplitterConverter}, ConverterParameter='Y', Mode=OneWay}" 
                            OffsetZ="{Binding Position, Converter={StaticResource Point3DToDoubleSplitterConverter}, ConverterParameter='Z', Mode=OneWay}"/>-->
                        <TranslateTransform3D
                            OffsetX="{DynamicResource BallPositionX}"
                            OffsetY="{DynamicResource BallPositionY}"
                            OffsetZ="{DynamicResource BallPositionZ}"/>
                    </Transform3DGroup>
                </local:Sphere3D.Transform>
            </local:Sphere3D> 
            <!--<ContainerUIElement3D x:Name="TiltControlX"
                                  MouseDown="TiltControlX_MouseDown">
                <ContainerUIElement3D.Transform>
                    <Transform3DGroup>
                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D Axis="1,0,0" Angle="90"/>
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>
                    </Transform3DGroup>
                </ContainerUIElement3D.Transform>
                <local:Cylinder3D>
                    <local:Cylinder3D.Transform>
                        <Transform3DGroup>
                            <ScaleTransform3D ScaleX="{DynamicResource BallSize}" ScaleY="{DynamicResource BallSize}" ScaleZ="{DynamicResource BallSize}"/>
                            <TranslateTransform3D OffsetX="-1.1" OffsetY="0"/>
                        </Transform3DGroup>
                    </local:Cylinder3D.Transform>
                </local:Cylinder3D>
            </ContainerUIElement3D>
            <ContainerUIElement3D x:Name="TiltControlY"
                                  MouseDown="TiltControlY_MouseDown">
                <ContainerUIElement3D.Transform>
                    <Transform3DGroup>
                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D Axis="1,0,0" Angle="90"/>
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>
                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D Axis="0,0,1" Angle="90"/>
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>
                    </Transform3DGroup>
                </ContainerUIElement3D.Transform>
                <local:Cylinder3D>
                    <local:Cylinder3D.Transform>
                        <Transform3DGroup>
                            <ScaleTransform3D ScaleX="{DynamicResource BallSize}" ScaleY="{DynamicResource BallSize}" ScaleZ="{DynamicResource BallSize}"/>
                            <TranslateTransform3D OffsetX="-1.1" OffsetY="0"/>
                        </Transform3DGroup>
                    </local:Cylinder3D.Transform>
                </local:Cylinder3D>
            </ContainerUIElement3D>
            <ContainerUIElement3D x:Name="TiltControlXI"
                                  MouseDown="TiltControlXI_MouseDown">
                <ContainerUIElement3D.Transform>
                    <Transform3DGroup>
                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D Axis="1,0,0" Angle="90"/>
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>
                    </Transform3DGroup>
                </ContainerUIElement3D.Transform>
                <local:Cylinder3D>
                    <local:Cylinder3D.Transform>
                        <Transform3DGroup>
                            <ScaleTransform3D ScaleX="{DynamicResource BallSize}" ScaleY="{DynamicResource BallSize}" ScaleZ="{DynamicResource BallSize}"/>
                            <TranslateTransform3D OffsetX="1.1" OffsetY="0"/>
                        </Transform3DGroup>
                    </local:Cylinder3D.Transform>
                </local:Cylinder3D>
            </ContainerUIElement3D>
            <ContainerUIElement3D x:Name="TiltControlYI"
                                  MouseDown="TiltControlYI_MouseDown">
                <ContainerUIElement3D.Transform>
                    <Transform3DGroup>
                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D Axis="1,0,0" Angle="90"/>
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>
                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D Axis="0,0,1" Angle="90"/>
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>
                    </Transform3DGroup>
                </ContainerUIElement3D.Transform>
                <local:Cylinder3D>
                    <local:Cylinder3D.Transform>
                        <Transform3DGroup>
                            <ScaleTransform3D ScaleX="{DynamicResource BallSize}" ScaleY="{DynamicResource BallSize}" ScaleZ="{DynamicResource BallSize}"/>
                            <TranslateTransform3D OffsetX="1.1" OffsetY="0"/>
                        </Transform3DGroup>
                    </local:Cylinder3D.Transform>
                </local:Cylinder3D>
            </ContainerUIElement3D>-->
            <ContainerUIElement3D IsEnabled="False" IsHitTestVisible="False" Visibility="Visible">
            <ModelVisual3D x:Name="StandModel">
                <ModelVisual3D.Content>
                    <Model3DGroup>
                        <AmbientLight Color="White"/>
                        <GeometryModel3D BackMaterial="{Binding Material, RelativeSource={RelativeSource Self}}">
                            <GeometryModel3D.Material>
                                <DiffuseMaterial Brush="#FF393939"/>
                            </GeometryModel3D.Material>
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D 
                                    Positions="0,0,0  0.1,0,-0.2  -0.1,0,-0.2  0,0.1,-0.2  0,-0.1,-0.2"
                                    TriangleIndices="0 1 3  0 2 4  0 2 3 0 1 4" />
                            </GeometryModel3D.Geometry>
                        </GeometryModel3D>
                    </Model3DGroup>
                </ModelVisual3D.Content>
            </ModelVisual3D>
            <ModelVisual3D  x:Name="TiltHelperModel">
                <local:Plate3D
                BackMaterial="{Binding Material, RelativeSource={RelativeSource Self}}">
                    <local:Plate3D.Material>
                        <DiffuseMaterial>
                            <DiffuseMaterial.Brush>
                                <ImageBrush ImageSource=".\Shapes\PlateTextureWhite.png" Opacity=".2"/>
                            </DiffuseMaterial.Brush>
                        </DiffuseMaterial>
                    </local:Plate3D.Material>
                </local:Plate3D>
                <local:Plate3D
                BackMaterial="{Binding Material, RelativeSource={RelativeSource Self}}">
                    <local:Plate3D.Material>
                        <DiffuseMaterial>
                            <DiffuseMaterial.Brush>
                                <ImageBrush ImageSource=".\Shapes\PlateTextureWhite.png" Opacity=".2"/>
                            </DiffuseMaterial.Brush>
                        </DiffuseMaterial>
                    </local:Plate3D.Material>
                    <local:Plate3D.Transform>
                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D Axis="1,0,0" Angle="90"/>
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>
                    </local:Plate3D.Transform>
                </local:Plate3D>
                <local:Plate3D
                BackMaterial="{Binding Material, RelativeSource={RelativeSource Self}}">
                    <local:Plate3D.Material>
                        <DiffuseMaterial>
                            <DiffuseMaterial.Brush>
                                <ImageBrush ImageSource=".\Shapes\PlateTextureWhite.png" Opacity=".2"/>
                            </DiffuseMaterial.Brush>
                        </DiffuseMaterial>
                    </local:Plate3D.Material>
                    <local:Plate3D.Transform>
                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D Axis="0,1,0" Angle="90"/>
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>
                    </local:Plate3D.Transform>
                </local:Plate3D>
            </ModelVisual3D>
            </ContainerUIElement3D>
        </Viewport3D>
        <ResizeGrip HorizontalAlignment="Right" d:LayoutOverrides="Height" VerticalAlignment="Bottom" MouseDown="ResizeGrip_MouseDown"/>
    </Grid>
</UserControl>